package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.common.utils.PageUtils;
import com.atguigu.spzx.product.entity.Product;
import com.atguigu.spzx.product.service.impl.ProductServiceImpl;
import com.atguigu.spzx.product.vo.ProductDetailsRespVo;
import com.atguigu.spzx.product.vo.ProductSkuQueryReqVo;
import com.atguigu.spzx.product.vo.ProductSkuQueryRespVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * ProductController
 * </p>
 *
 * @author flyduck
 * @since 2023/11/3
 */
@Api(tags = "商品管理接口")
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductServiceImpl productService;

    @ApiOperation("商品详情")
    @GetMapping("/item/{skuId}")
    public Result getProductSkuBySkuId(@PathVariable Long skuId){
        ProductDetailsRespVo respVo = productService.getProductSkuBySkuId(skuId);
        return Result.ok(respVo);
    }

    @ApiOperation("分页查询")
    @GetMapping(value = "/{page}/{limit}")
    public Result getProductPageByQuery(@PathVariable Integer page,
                                        @PathVariable Integer limit,
                                        ProductSkuQueryReqVo vo){
        Page<Product> pageParam = new Page<>(page,limit);
        Page<ProductSkuQueryRespVo> pageModel = productService.getProductPageByQuery(pageParam,vo);
        PageInfo<ProductSkuQueryRespVo> pageInfo = PageUtils.convertToPageInfo(pageModel);
        return Result.ok(pageInfo);

    }
}
